package com.yx.yinshanjinniu.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.core.content.ContextCompat;


import com.yx.yinshanjinniu.R;
import com.zc.mychart.model.GoodsAllBean;

import java.util.List;

public class PopupGroupAdapter extends CommonAdapter<GoodsAllBean> {

    private int mPosition = -1;

    public PopupGroupAdapter(Context context, List list) {
        super(context, list);
    }

    public void setChecked(int position) {
        this.mPosition = position;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_product_name, parent, false);
            viewHolder = new ViewHolder(convertView);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(position);
        return convertView;
    }

    class ViewHolder {
        private TextView tv_product_name;

        public ViewHolder(View rootView) {
            rootView.setTag(ViewHolder.this);
            tv_product_name = rootView.findViewById(R.id.tv_product_name);
        }

        void setData(int position) {
            if (position == mPosition) {
                tv_product_name.setTextColor(ContextCompat.getColor(mContext,R.color.color_blue_07));
            } else {
                tv_product_name.setTextColor(ContextCompat.getColor(mContext,R.color.color_gray_03));
            }

            GoodsAllBean mGroupBean = mDatas.get(position);
            tv_product_name.setText(mGroupBean.pro_name);
        }
    }
}
